home *** CD-ROM | disk | FTP | other *** search
/ Windows 6-Pak - Disc 5 / Windows 6-Pak (InfoMagic) (Disc 5) (1999).ISO / JAVA-Programming-Tools / jtk101c.exe / DISK2 / clientio.ht_ / clientio.ht
Encoding:
Text File  |  1998-08-24  |  9.6 KB  |  262 lines

  1. <html>
  2.   <head>
  3.     <title>Class ClientIO - Evans Java Toolkit</title>
  4.     <meta name="description" content="Evans Programming Java Toolkit - ClientIO">
  5.     <meta name="keywords" content="IO, java, read, write, server, client>
  6.     <meta name="DESIGN" content="Evans Programming, Hoffman Estates, IL">
  7.   </head>
  8.  
  9.   <body bgcolor="#FFFFFF" link="#FF0000" vlink="#800000" alink="#FF00FF">
  10.  
  11. <!--INCLUDESTART="JTCLSHDR.TXT"-->
  12.       <center>
  13.         <font face="Arial" size="5" color="0000FF">
  14.           <strong>Evans Programming Java Toolkit</strong><br>
  15.         </font>
  16.       </center>
  17.       
  18.       <center>
  19.         <font size="-2" face="Arial" color="FF0000">
  20.           <strong>
  21.             <a href="../jtkit.htm", target="_top">Java Toolkit Page</a> |
  22.             <a href="../softwr.htm", target="_top">Software</a> |
  23.             <a href="../index.html", target="_top">Home</a><br>
  24.           </strong>
  25.         </font>
  26.       </center>
  27. <!--INCLUDESTOP="JTCLSHDR.TXT"-->
  28. <!--INCLUDESTART="JTPGIDX.TXT"-->
  29.       <center>
  30.         <font size="-2" face="Arial" color="FF0000">
  31.           <strong>
  32.             <a href="#DESCRIPTION">Description</a> |
  33.             <a href="#EXAMPLES">Examples</a> |
  34.             <a href="#CONSTRUCTORS">Constructors</a> |
  35.             <a href="#METHODS">Methods</a>
  36.           </strong>
  37.         </font>
  38.       </center>
  39. <!--INCLUDESTOP="JTPGIDX.TXT"-->
  40. <!--INCLUDESTART="JTPGNAV.TXT"-->
  41.  
  42.     
  43.     <a href="formtool.htm">Previous</a> 
  44.     <a href="serverio.htm">Next</a> 
  45.     <a href="classidx.htm">Index</a><br>
  46.                                  
  47. <!--INCLUDESTOP="JTPGNAV.TXT"-->
  48.  
  49.     <hr>
  50.     <h1>Class ClientIO</h1>
  51.  
  52.     <pre>
  53. public class evans.toolkit.<strong>ClientIO</strong>
  54. {
  55.     // Constructors
  56.     public <strong>ClientIO</strong>();
  57.     
  58.     // Methods
  59.     public String <strong>talk</strong>(URL serversideEXE, String data);
  60.     public boolean <strong>getLastResult</strong>();
  61. }   </pre>
  62.  
  63.     <hr>
  64.     <a name="DESCRIPTION"><img src="descript.gif" width=220 height=60 alt="Description"></a>
  65.     <p>
  66.       The primary function of ClientIO is to write to a web server file from a java applet.
  67.       ClientIO can also receive data in the form of a response.
  68.       A method is provided to test the results of the most recent write
  69.       attempt.
  70.     </p>
  71.  
  72.     <p>
  73.       <strong>NOTE:</strong> A server side executable, named <a href="serverio.htm">serverio.exe</a>, is provided with the Evans Java Toolkit.
  74.       It, or another CGI program, is required to accomplish java to web server i/o. The ClientIO class is
  75.       the client side piece.
  76.     </p>
  77.  
  78.     <hr>
  79.     <a name="EXAMPLES"><img src="example.gif" width=220 height=60 alt="Examples"></a>
  80.     <h3>Write To A Web Server</h3>
  81.  
  82.     <pre>
  83.     // Write psvText and return a boolean indicating success or failure
  84.     import java.net.*;
  85.     import java.applet.*;
  86.     import evans.toolkit.*;
  87.     
  88.     public class io extends Applet 
  89.     {
  90.         public void init()
  91.         {
  92.             boolean bResult = false;
  93.             bResult = clientIOexample("This is web server write example" + "\n");
  94.         }
  95.     
  96.         // Write psvText and return a boolean indicating success or failure
  97.         private boolean clientIOexample(String psvText)
  98.         {
  99.             URL url = null;
  100.             
  101.             // Construct a ClientIO object, oClientIO
  102.             ClientIO oClientIO = new ClientIO();
  103.             
  104.             // Initialize reply variable
  105.             String svAnswer = "";
  106.             
  107.             // We will write to the serverio.exe which will "post" the data
  108.             // to the file specified in the serverio.ini file (located in 
  109.             // the cgi-bin directory).
  110.             try
  111.             {
  112.                 url = new URL("http://www.evans-programming.com/cgi-bin/serverio.exe");
  113.             }
  114.             catch (MalformedURLException me)
  115.             {
  116.             }
  117.             
  118.             // Write the data and get back a response
  119.             svAnswer = oClientIO.talk(url, psvText);
  120.             
  121.             // Return boolean result. Note: svAnswer is not returned in this example
  122.             return oClientIO.getLastResult();
  123.         }
  124.     }</pre>
  125.  
  126.     <dl>
  127.       <dt><h3>Read From A Web Server</h3>
  128.       <dd><p><strong>Note:</strong> Reading from a web server file is NOT part of the
  129.           ClientIO class. The example provided here is for educational value only.</p>
  130.     </dl>
  131.  
  132.     <pre>
  133.     // Read and return data from a file on a web server
  134.     // urlFile is a URL specifying the full file pathname of the file to read
  135.     private String readFromFile(URL urlFile);
  136.     {
  137.         try
  138.         {
  139.             String svAns = "";
  140.             String svIncoming = "";
  141.  
  142.             URLConnection connection = urlFile.openConnection();
  143.     
  144.             connection.setDoInput(true);
  145.             connection.setDoOutput(false);
  146.             connection.setAllowUserInteraction(false);
  147.     
  148.             DataInputStream inStream = new DataInputStream(connection.getInputStream());
  149.             while ((svIncoming = inStream.readLine()) != null)
  150.             {
  151.                 svAns += svIncoming;
  152.             }
  153.             inStream.close();
  154.         }
  155.         catch (IOException ioe)
  156.         {
  157.         }
  158.         return svAns;
  159.     }</pre>
  160.  
  161.     <hr>
  162.     <a name="CONSTRUCTORS"><img src="constrct.gif" width=220 height=60 alt="Constructors"></a>
  163.  
  164.     <dl>
  165.       <dt><h3>ClientIO</h3>
  166.       <dd><code>public <strong>ClientIO</strong>();</code>
  167.       <dd><p>Constructs a ClientIO object.</p>
  168.     </dl>
  169.  
  170.     <hr>
  171.     <a name="METHODS"><img src="methods.gif" width=220 height=60 alt="Methods"></a>
  172.  
  173.     <dl>
  174.       <dt><h3>talk</h3>
  175.       <dd><code>String <strong>talk</strong>(URL serversideEXE, String data);</code>
  176.       <dd><p>Passes data to the <a href="serverio.htm">serverio.exe</a> serverside executable that in turn "posts"
  177.           the data to the appropriate file. A <a href="serverio.htm">serverio.ini</a> file on the
  178.           web server specifies the actual file where <a href="serverio.htm">serverio.exe</a> will "post".
  179.           A String response is returned.</p>
  180.           <p>The file is created if it does not exist, otherwise the data is appended
  181.           to the existing file.</p>
  182.       <dl>
  183.         <dt><h4>Parameters:</h4>
  184.         <dd><strong>serversideEXE</strong> - URL - The serverside executable that will post the data.
  185.         <dd><strong>data</strong> - String - The data to write.
  186.       </dl>
  187.       <p></p>
  188.  
  189.       <dl>
  190.         <dt><h4>Notes:</h4>
  191.         <dd><p>If an error occurs in serverio.exe and not in the ClientIO
  192.             class, the getLastResult() method will mistakenly return true. This is because
  193.             ClientIO is only aware of errors that occur within the ClientIO class. If
  194.             you want to be absolutely sure of the results, parse talk()'s return
  195.             string using the following information.</p>
  196.         <ul>
  197.           <li>"Transaction complete" is returned (initiated by serverio.exe) if ClientIO and serverio.exe are successful.
  198.           <li>"ERROR: MalformedURLException: " + (additional information) is returned from the ClientIO class if an error occurs within ClientIO.
  199.           <li>"ERROR: IOException: " + (additional information) is returned from the ClientIO class if an error occurs within ClientIO.
  200.           <li>"ERROR: Can't write transaction file, serverio.ini not found" is returned from serverio.exe if an error occurs within serverio.exe.
  201.           <li>"ERROR: Can't write transaction file" is returned from serverio.exe if an error occurs within serverio.exe.
  202.         </ul>
  203.           <p>In most applications, parsing the return string should not be necessary once
  204.           the serverio.exe program has been correctly installed and tested. 
  205.           ClientIO's getLastResult() method does not check the serverio.exe response data as part of it's decision
  206.           making process because another serverside program may be used in it's place.</p>
  207.       </dl>
  208.     </dl>
  209.  
  210.     <dl>
  211.       <dt><h3>getLastResult</h3>
  212.       <dd><code>boolean <strong>getLastResult</strong>();</code>
  213.       <dd><p>Returns true or false to indicate the success or failure of the
  214.           last write attempt by talk().</p>
  215.     </dl>
  216.     
  217.     <hr>
  218.  
  219. <!--INCLUDESTART="JTPGNAV.TXT"-->
  220.  
  221.     
  222.     <a href="formtool.htm">Previous</a> 
  223.     <a href="serverio.htm">Next</a> 
  224.     <a href="classidx.htm">Index</a><br>
  225.                                  
  226. <!--INCLUDESTOP="JTPGNAV.TXT"-->
  227. <!--INCLUDESTART="JTPGIDX.TXT"-->
  228.       <center>
  229.         <font size="-2" face="Arial" color="FF0000">
  230.           <strong>
  231.             <a href="#DESCRIPTION">Description</a> |
  232.             <a href="#EXAMPLES">Examples</a> |
  233.             <a href="#CONSTRUCTORS">Constructors</a> |
  234.             <a href="#METHODS">Methods</a>
  235.           </strong>
  236.         </font>
  237.       </center>
  238. <!--INCLUDESTOP="JTPGIDX.TXT"-->
  239. <!--INCLUDESTART="JTCLSFTR.TXT"-->
  240.     <center>
  241.       <font size="-2" face="Arial" color="FF0000">
  242.         <strong>
  243.           <a href="../jtkit.htm", target="_top">Java Toolkit Page</a> |
  244.           <a href="../softwr.htm", target="_top">Software</a> |
  245.           <a href="../index.html", target="_top">Home</a><br>
  246.         </strong>
  247.       </font>
  248.     </center>
  249.  
  250.     <p></p>
  251.     <font size="-1">Evans Programming Java Toolkit HTML Document<br>
  252.       Generated March 15, 1998<br>
  253.       Revised Februrary 5, 1999<br>
  254.       Copyright 1998-1999 Evans Programming<br>
  255.       Send comments or corrections to <a href="mailto:davidLevans@megsinet.net">davidLevans@megsinet.net</a>
  256.     </font>
  257. <!--INCLUDESTOP="JTCLSFTR.TXT"-->
  258.  
  259.     </font>
  260.   </body>
  261. </html>
  262.